package com.young.shop.api.controller;

import com.young.shop.api.service.CommentService;
import com.young.shop.pojo.entity.Comment;
import com.young.shop.pojo.entity.Goods;
import com.young.shop.pojo.vo.BaseRespVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "评论业务接口")
@RestController
@RequestMapping("/comment")
public class CommentController extends BaseController{
    @Autowired
    CommentService commentService;

    @ApiOperation("查询要评论商品")
    @GetMapping("/inquiry")
    @ApiImplicitParam(paramType = "query", name = "orderId", value = "订单id", dataType = "Long")
    public BaseRespVO inquiry(@RequestParam("orderId")Long orderId){
        System.out.println(orderId);
        try {
            List<Goods> goods = commentService.inquiryByOrderId(orderId);
            return convertSuccessResult(goods);
        }catch (RuntimeException e){
            String message = e.getMessage();
            return convertErrorResult(message);
        }
    }

    @ApiOperation("评论商品")
    @PostMapping("/particulars")
    public BaseRespVO particulars(String userName,Long goodsId,int satisfaction,String evaluate){
        Comment comment = new Comment();
        comment.setUserName(userName);
        comment.setGoodsId(goodsId);
        comment.setSatisfaction(satisfaction);
        comment.setEvaluate(evaluate);
//        System.out.println(comment);
        try {
            int i = commentService.commentGoods(comment);
            return convertSuccessResult(i);
        }catch (RuntimeException e) {
            return convertErrorResult(e.getMessage());
        }
    }
}
